package com.wing.purchase.service;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.product.model.entity.ProductItem;
import com.wing.purchase.dao.PurQualityTestingTaskDetailDao;
import com.wing.purchase.model.entity.PurQualityTestingTaskDetail;
import com.wing.purchase.model.entity.PurQualityTestingTaskDetailValue;
import com.wing.purchase.model.response.PurQualityTestingTaskDetailSearchVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 采购-质检任务-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class PurQualityTestingTaskDetailServiceImpl extends ServiceImpl<PurQualityTestingTaskDetailDao, PurQualityTestingTaskDetail> implements PurQualityTestingTaskDetailService {

    @Resource
    private PurQualityTestingTaskDetailValueService purQualityTestingTaskDetailValueService;

    /**
     * 查询质检项目
     * @param productDetailId 物料di
     * @param type 质检类型
     * @param qualityTestingCategoryId 质检分类id
     * @return
     */
    @Override
    public List<ProductItem> getQualityInfoBy(Long productDetailId, String type, Long qualityTestingCategoryId) {
        return this.baseMapper.getQualityInfoBy(productDetailId,type,qualityTestingCategoryId);
    }

    /**
     * 查询质检任务详情
     * @param pg
     * @param params
     * @return
     */
    @Override
    public IPage<PurQualityTestingTaskDetailSearchVo> pageList4app(Page<PurQualityTestingTaskDetailSearchVo> pg, Map<String, Object> params) {
        List<PurQualityTestingTaskDetailSearchVo> taskList = this.baseMapper.pageList4app(pg,params);
        pg.setRecords(taskList);
        return pg;
    }

    /*
     * 查询采购详情
     */
    @Override
    public PurQualityTestingTaskDetailSearchVo detail(String recordId) {
        PurQualityTestingTaskDetailSearchVo detail = this.baseMapper.getDetail(recordId);
        if (ObjectUtil.isNotEmpty(recordId)) {
            Long id = detail.getId();
            QueryWrapper<PurQualityTestingTaskDetailValue> valueQueryWrapper = new QueryWrapper<>();
            valueQueryWrapper.eq("testing_task_detail_id", id);
            valueQueryWrapper.eq("is_deleted", false);
            List<PurQualityTestingTaskDetailValue> detailValues = this.purQualityTestingTaskDetailValueService.list(valueQueryWrapper);
            detail.setDetailValues(detailValues);
        }
        return detail;
    }
}
